import { Row, Col } from 'antd';
import { Fragment } from 'react';
import { axhelper } from '@/shared/axhelper';

export const AxGridLayout = props => {
  const { items = [], hiddenItems = [] } = props;
  const rows = [];
  let cols = [];
  let nextRow = false;
  const len = items.length - 1;

  items.forEach((i, idx) => {
    if (i === false) {
      return;
    }
    /** 占整行 */
    if (i.props.wholerow === 'two' || i.props.wholerow === 'two') {
      cols.push(<Col span={24}>{i}</Col>);
      nextRow = true;
    } else {
      cols.push(<Col span={12}>{i}</Col>);
      if (cols.length === 2) {
        nextRow = true;
      }
    }
    if (nextRow === true || len === idx) {
      rows.push(
        <Row key={'row' + rows.length}>
          {cols.map((i, idx) => (
            <Fragment key={idx}>{i}</Fragment>
          ))}
        </Row>,
      );
      cols = [];
      nextRow = false;
    }
  });
  if (hiddenItems.length > 0)
    rows.push(
      <div style={{ display: 'none' }} key={'row' + rows.length}>
        {hiddenItems.map((i, idx) => (
          <div key={len + idx}>{i}</div>
        ))}
      </div>,
    );
  return <>{rows}</>;
};
